/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.simba.utils.tree;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.regex.Pattern;

/**
 *
 * @author ngonga
 */
public class WordScore {
    HashMap<String, Double> sentimentList;
    public void loadSentiments(String file)
    {
        sentimentList = new HashMap<String, Double>();
        try
        {
            BufferedReader reader = new BufferedReader(new FileReader(file));
            String line = reader.readLine();
            String[] split;
            double pos, neg, score;
            while(line!=null)
            {
                try
                {
                    split = line.split(Pattern.quote(","));
                    pos = Double.parseDouble(split[1]);
                    neg = Double.parseDouble(split[2]);
                    score = Math.pow(2, pos-neg) - 1;
                    sentimentList.put(split[0], score);
                    System.out.println(split[0]+ " "+score);
                }
                catch(Exception es)
                {
                    es.printStackTrace();
                }
                
                line = reader.readLine();
            }
            
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    public double getScore(String word)
    {
        if(word.contains("-")) word = word.substring(0, word.lastIndexOf("-"));
        if(sentimentList.containsKey(word)) return sentimentList.get(word);
        return 0;
    }
    
    public static void main (String[] args)
    {
        WordScore ws = new WordScore();
        //ws.loadSentiments("D:/Downloads/twitter_sentiment_list.csv");
        ws.loadSentiments("c:\\Users\\lejtovicz\\Downloads\\twitter_sentiment_list_2.csv");
    }
}
